﻿using System.IO;
using XMLConsoleApplication3;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace XMLConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            ufinterface city1 = new ufinterface()
            {
                roottag = "sendresult",
                successful = "N",
                isexchange = "Y",
                sendresult = new sendresult()
                {
                    billpk = "5162",
                    bdocid = "1221",
                    filename = "abbc",
                    resultcode = "31003",
                    resultdescription = "从输入流转换document出错：请检验文档格式。",
                    content = DateTime.Now.ToString()
                }
            };

            XMLHelper.SaveToXml(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "configs\\NCResponse.xml"), city1);

            Main2();

            Console.ReadLine();
        }
        static void Main2()
        {
            ufinterface city1 = new ufinterface();
            var dd = XMLHelper.LoadFromXml(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "configs\\NCResponse.xml"), city1.GetType());

            Print(dd);
        }


        public static void Print(object model)
        {
            var t = model.GetType();

            foreach (PropertyInfo pi in t.GetProperties())
            {
                object value1 = pi.GetValue(model, null);

                if (value1 as IEntity != null)
                {
                    Console.WriteLine("==========================================");
                    Print(value1);
                }

                string name = pi.Name;

                Console.WriteLine(string.Format("{1}={0}", value1, name));
            }
        }
    }
}
